package com.boot.rabbitmqserver.sender;

import com.boot.commons.option.SexEnum;
import com.boot.commons.vo.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HelloSender  {

    /**
     * spring默认的消息发送者
     */
    @Autowired
    private AmqpTemplate rabbitTemplate;


    public void send() {

        // for (int i = 0; i < 100; i++) {
        //     this.rabbitTemplate.convertAndSend("hello", "消息:" + i);
        // }


        User user = new User().setUserName("洪殷").setSex(SexEnum.MAN).setId(111);


        this.rabbitTemplate.convertAndSend("object", user);
    }

    // 发送给交换机
    public void send1() {
        String context = "hi, i am message 1";
        System.out.println("Sender : " + context);

        this.rabbitTemplate.convertAndSend("exchange", "topic.message", context);
    }

    // 发送给交换机
    public void send2() {
        String context = "hi, i am messages 2";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("exchange", "topic.messages111", context);
    }

    
    public void send4() {
        /** 
        * Desc: 广播模式,发送给fanoutExchange   ||
        * Param: []    ||
        * Return: void    ||
        */ 
        
        String context = "hi, fanout msg ";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("fanoutExchange", "", context);
    }

}